* Table C7: Program characteristics by excess self-funded capacity at the benchmark
* Helper file

clear all
use "${data_applications}", clear

gen abc = admitted == 1 & priorityscore < priorityscore_cutoff

merge n:1 id using "${data_srda}"

drop admitted
gen admitted = contract_id == contract_id_orig

drop priorityscore_cutoff
replace priorityscore = . if priorityscore <= 0
replace priorityscore = . if admitted == 0
bys contract_id: egen priorityscore_cutoff = min(priorityscore)

keep id contract_id program_id funding karkod szaknev program_level munkarend /// 
	field_study szekhely szakkod kepztelep priorityscore capacity_class ///
	program_county abc admitted priorityscore_cutoff
	
collapse (sum) abc admitted, by(contract_id program_id funding karkod szaknev program_level priorityscore_cutoff	munkarend field_study szekhely szakkod kepztelep capacity_class program_county)

rename admitted admitted_applicants
merge 1:1 contract_id using "${data_capacities}"
gen capacity_benchmark = capacity_wo_ABC_benchmark + abc
drop capacity_wo_ABC_benchmark

replace capacity_benchmark = admitted_applicants if capacity_benchmark < admitted_applicants

bys program_id: gen dual = _N

keep if dual == 2

replace priorityscore_cutoff = 78 if funding == 1 & ///
	priorityscore_cutoff == . & ///
	(program_level == 1 |program_level == 3)
replace priorityscore_cutoff = . if funding == 2	

bys program_id: egen ps_cutoff = max(priorityscore_cutoff)

gen potential = capacity_benchmark - admitted_applicants if dual == 2 & funding == 2
gen potential_binary = potential > 0

keep if funding == 2

gen ba = program_level == 1
lab var ba "BA/BSc program"
gen tertiary = program_level == 5
lab var tertiary "Tertiary vocational program"
gen fulltime = munkarend == 1
lab var fulltime "Full-time"
gen periphery = kepztelep != "Budapest"
lab var periphery "Periphery"
gen field_4 = capacity_class == 4
lab var field_4 "Field: economics and business"
gen field_19 = capacity_class == 19
lab var field_19 "Field: tertiary vocational"
gen field_3 = capacity_class == 3
lab var field_3 "Field: humanities"
gen field_8 = capacity_class == 8
lab var field_8 "Field: engineering"
gen field_17 = capacity_class == 17
lab var field_17 "Field: natural science"
gen field_18 = capacity_class == 18
lab var field_18 "Field: social science"



